# 构建镜像: 
# docker build -t xbear/PHP_IMAGE .
FROM PHP_IMAGE

# 安装扩展 
## apk add 扩展
## docker-php-ext-install 扩展
## pecl install 扩展, 安装后需要 docker-php-ext-enable 开启
## 需要编译的扩展

# 切换国内源 mirrors.tencent.com mirrors.aliyun.com mirrors.ustc.edu.cn
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories \
  # 更新系统
  && apk update \
  # gd 图库处理
  && apk add --no-cache freetype-dev libjpeg-turbo-dev libpng-dev \
  && docker-php-ext-configure gd --with-freetype --with-jpeg \
  && docker-php-ext-install gd \
  # bcmath 任意精度数学库计算
  && docker-php-ext-install bcmath \
  # imap 接收邮件
  && apk add --no-cache imap-dev \
  && docker-php-ext-install imap \
  # zip
  && apk add --no-cache libzip libzip-dev \
  && docker-php-ext-install zip \
  # composer
  && curl -sS https://getcomposer.org/installer | php \
  && mv composer.phar /usr/local/bin/composer \
  && chmod -R 777 /usr/local/bin/composer \
  && composer config -g repo.packagist composer https://mirrors.tencent.com/composer/ \
  # mysql pdo
  && docker-php-ext-install pdo pdo_mysql \
  # pecl 依赖
  && apk add --no-cache pcre-dev $PHPIZE_DEPS \
  && pecl channel-update pecl.php.net \
  # pecl 安装 redis, swoole 扩展
  && pecl install redis \
  && pecl install swoole \
  && apk add librdkafka-dev \
  && pecl install rdkafka \
  # 启用扩展
  && docker-php-ext-enable redis swoole rdkafka \
  # 删除 pecl 安装时产生临时文件
  && rm -rf /tmp/pear \
  # 加载配置文件
  && mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"